package com.fancy.middleware.netty.config;


import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerSocketChannel;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@ConditionalOnExpression(value = "#{!(T(io.netty.util.internal.PlatformDependent).isAndroid() || T(io.netty.util.internal.PlatformDependent).isWindows() || T(io.netty.util.internal.PlatformDependent).isOsx())}")
public class EpollNettyConfiguration {

    @Bean("bossEventLoopGroup")
    @ConditionalOnMissingBean(name = "bossEventLoopGroup")
    public EventLoopGroup bossEventLoopGroup(){
        return new EpollEventLoopGroup();
    }

    @Bean("workerEventLoopGroup")
    @ConditionalOnMissingBean(name = "workerEventLoopGroup")
    public EventLoopGroup workerEventLoopGroup(){
        return new EpollEventLoopGroup();
    }

    @Bean
    @ConditionalOnMissingBean
    public Class channelClazz() {
        return EpollServerSocketChannel.class;
    }
}
